package de.bloxel.controller;

import de.bloxel.core.LoadEvent;
import de.bloxel.core.SaveEvent;
import de.bloxel.ui.BloxelApplication;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

public class ControllerMenu implements ScreenController {

  private Nifty nifty;
  private Screen screen;
  private final BloxelApplication bloxelApplication;

  public ControllerMenu(final BloxelApplication bloxelApplication) {
    this.bloxelApplication = bloxelApplication;
  }

  @Override
  public void bind(final Nifty niftyParam, final Screen screenParam) {
    nifty = niftyParam;
    screen = screenParam;

  }

  public void closeMenu() {
    bloxelApplication.getNiftyDisplay().getNifty().gotoScreen("hud");
  }

  public void exit() {
    nifty.createPopup("popupExit");
    nifty.showPopup(screen, "popupExit", null);
  }

  public void exitGame() {
    bloxelApplication.stop();
  }

  public void loadGame() {
    bloxelApplication.eventManager.queueEvent(new LoadEvent("scene.save"));
    closeMenu();
  }

  @Override
  public void onEndScreen() {
    // TODO Auto-generated method stub

  }
  @Override
  public void onStartScreen() {
    // TODO Auto-generated method stub

  }

  public void saveGame(){
    bloxelApplication.eventManager.queueEvent(new SaveEvent("scene.save"));
    closeMenu();
  }

  public void startGame(){
    closeMenu();
  }

}
